﻿package view.component
{
    import __AS3__.vec.*;
    import com.greensock.*;
    import com.sh.game.util.*;
    import flash.display.*;
    import flash.utils.*;
    import morn.core.components.*;
    import pluginfw.*;

    public class Announce extends Sprite
    {
        private var maxCount:int = 5;
        private var msgStack:Vector.<String>;
        private var curShowCount:int = 0;
        private var labelDic:Dictionary;
        private var delayTimer:int = 0;
        private var delayShowing:Boolean = false;
        private var animateTime:Number = 0.5;
        private var closeTimer:int = 0;

        public function Announce()
        {
            this.msgStack = new Vector.<String>;
            this.labelDic = new Dictionary();
            return;
        }// end function

        public function add(param1:Object) : void
        {
            var _loc_10:String = null;
            var _loc_2:* = param1 as Array;
            if (_loc_2 == null || _loc_2.length == 0)
            {
                return;
            }
            var _loc_3:* = _loc_2.pop();
            var _loc_4:* = ConfigDictionary.data.announce[_loc_3];
            if (ConfigDictionary.data.announce[_loc_3] == null)
            {
                return;
            }
            var _loc_5:* = _loc_4.text;
            var _loc_6:* = _loc_4.color;
            if (_loc_4.color == null)
            {
                return;
            }
            var _loc_7:* = _loc_6.split("#");
            if (!_loc_5 || _loc_5 == "")
            {
                return;
            }
            var _loc_8:int = 0;
            while (_loc_8 < _loc_2.length)
            {
                
                _loc_10 = "ffcc00";
                if (_loc_7[_loc_8])
                {
                    _loc_10 = _loc_7[_loc_8];
                }
                _loc_2[_loc_8] = Html.covert("{" + _loc_10 + "#16#" + _loc_2[_loc_8] + "}");
                _loc_8++;
            }
            var _loc_9:* = "<font size=\'16\'>" + StringUtil.substitute(_loc_5, _loc_2) + "</font>";
            this.msgStack.push(_loc_9);
            this.checkShow();
            return;
        }// end function

        public function checkShow() : void
        {
            if (this.delayShowing)
            {
                return;
            }
            if (this.curShowCount >= this.maxCount)
            {
                return;
            }
            if (this.msgStack.length <= 0)
            {
                return;
            }
            this.delayShowing = true;
            this.delayTimer = setTimeout(this.doDelay, this.animateTime * 1000);
            var _loc_2:String = this;
            var _loc_3:* = this.curShowCount + 1;
            _loc_2.curShowCount = _loc_3;
            if (this.closeTimer == 0)
            {
                this.closeTimer = setInterval(this.checkClose, 1000);
            }
            var _loc_1:* = this.msgStack.shift();
            this.doShow(_loc_1);
            return;
        }// end function

        private function checkClose() : void
        {
            var _loc_1:Object = null;
            var _loc_2:Object = null;
            var _loc_3:int = 0;
            for (_loc_1 in this.labelDic)
            {
                
                _loc_2 = this.labelDic[_loc_1];
                _loc_3 = int(_loc_2.closeTime) + 1;
                if (_loc_3 >= 10 - this.maxCount)
                {
                    TweenLite.to(_loc_1, 0.5, {alpha:0, onComplete:this.doKillShow, onCompleteParams:[_loc_1]});
                    continue;
                }
                _loc_2.closeTime = _loc_3;
            }
            return;
        }// end function

        public function doKillShow(param1:Label) : void
        {
            TweenLite.killTweensOf(param1);
            this.removeChild(param1);
            delete this.labelDic[param1];
            param1 = null;
            var _loc_2:String = this;
            var _loc_3:* = this.curShowCount - 1;
            _loc_2.curShowCount = _loc_3;
            this.checkShow();
            return;
        }// end function

        private function doDelay() : void
        {
            if (this.delayTimer > 0)
            {
                clearTimeout(this.delayTimer);
                this.delayTimer = 0;
            }
            this.delayShowing = false;
            clearTimeout(this.delayTimer);
            this.delayTimer = 0;
            this.checkShow();
            return;
        }// end function

        private function doShow(param1:String) : void
        {
            var _loc_4:Object = null;
            var _loc_5:TimelineLite = null;
            var _loc_6:Object = null;
            var _loc_7:int = 0;
            var _loc_2:* = new Label();
            _loc_2.color = 16763904;
            _loc_2.stroke = "0x0";
            _loc_2.isHtml = true;
            _loc_2.text = param1;
            var _loc_3:* = (-_loc_2.width) / 2;
            _loc_2.x = _loc_3;
            this.addChild(_loc_2);
            for (_loc_4 in this.labelDic)
            {
                
                _loc_6 = this.labelDic[_loc_4];
                _loc_7 = int(_loc_6.index) + 1;
                TweenLite.to(_loc_4, this.animateTime, {y:(-_loc_7) * 30});
                _loc_6.index = _loc_7;
            }
            this.labelDic[_loc_2] = {index:0, closeTime:0};
            _loc_5 = new TimelineLite();
            _loc_5.append(new TweenLite(_loc_2, 0.1, {scaleX:1.5, scaleY:1.5, x:_loc_3 * 1.5, y:-20}));
            _loc_5.append(new TweenLite(_loc_2, 0.1, {scaleX:1, scaleY:1, y:0, x:_loc_3}));
            return;
        }// end function

    }
}
